﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DetailPlayer.ascx.cs"
    Inherits="Framework.Portal.Layouts.Client.Components.Teenio.DetailPlayer" %>
<div class="col2">
    <div class="detail_event">
        <h1 class="title_event">
            <%= MENUNAME %></h1>
        <div class="left_sapo">
            <asp:Image ID="imgAvatar" BorderWidth="1" runat="server" Width="110" Height="90"
                ImageUrl="/Uploads/117/1/PreAvatar/ava3.jpg" />            
        </div>
        <!--end:left_sapo -->
        <div class="right_sapo">
            <h2 class="title_details">
                <asp:Literal ID="lblTitle" runat="server"></asp:Literal></h2>
            <span class="view">Lượt nghe:
                <asp:Literal ID="lblView" runat="server" Text="123"></asp:Literal>
                | Ngày gửi: <asp:Literal ID="lblCreateDate" runat="server"></asp:Literal>
            <br />
            <br />
            <p>
                <asp:Literal ID="lblContent" runat="server"></asp:Literal></p>
        </div>
        <!--end:right_sapo -->
        <br class="clear" />
        <center>
            <div id="MainPlayer">
            </div>
        </center>
        <script src="/ClientScript/Player/jwplayer.js" type="text/javascript"></script>
        <asp:Literal ID="lblPlayer" runat="server"></asp:Literal>
    </div>
    <!--end:detail_event-->
    <div class="share_social" id="boxLike">
        <div class="csslikeCommentl">
            <a href="javascript:;" onclick="DoVote();">Thích</a></div>
    </div>
    <div class="share_social">
        <span style="float: left; width: 45px; margin-top: 5px;">Chia sẻ</span>
        <script type="text/javascript" src="http://my.go.vn/js/share.js?v=10009"></script>
        <div id="blogs_sharetId">
        </div>
        <script type="text/javascript">
            var obj = {
                link: location.href
                , message: ""
                , picture: ""
                , title: ""
                , description: ""
                , name: "blogs.go.vn"
            }
            init_shareAll("blogs_sharetId", obj);
        </script>
    </div>
    <ul class="cmmt1" id="boxComment">
        <li id="write_0">
            <div id="inputCMTHidden" style="width: 100%; float: left;" onclick="ShowCommentBox();">
                <input name="" id="txttempRawContent" type="text" value="Viết bình luận" />
            </div>
            <div id="inputCMT" style="width: 100%; float: left;" onclick="HideCommentBox();">
                <textarea id="txtRawContent" rows="5" cols="150" style="width: 100%;"></textarea>
                <br />
                <a class="button fr" onclick="SendComent();" href="javascript:;"><span>Bình luận</span></a>
            </div>
        </li>
    </ul>
    <!--end:comemt-->
</div>
<script type="text/javascript">
    var curentUser = <%= currentUserId %>;
    $(document).ready(function () {
        var initEditor = function () {
            $("#txtRawContent").sceditorBBCodePlugin({
                toolbar: "bold,italic,underline,|,emoticon",
                style: "/ClientScript/sceditor/css/jquery.sceditor.default.min.css"
            });
        };
        initEditor();
        $("#inputCMT").hide();
        $("#inputCMTHidden").show();
    });
    function ShowCommentBox() {
        $("#inputCMT").show();
        $("#inputCMTHidden").hide();
        //txttempRawContent
        $("#txtRawContent").data("sceditor").focus();
    }
    function HideCommentBox() {
        if ($("#txtRawContent").data("sceditor").val().length <= 0) {
            $("#inputCMT").hide();
            $("#inputCMTHidden").show();
        }
    }
    function SendComent() {        
        var commentReturn;
        $.ajax({
            type: "POST",
            cache: false,
            url: "Resources.ashx?module=contribution&action=insertcomment",
            data: { "articleId": <%= articleId %>, "message": $("#txtRawContent").data("sceditor").val()},
            success: function (html) {
                commentReturn = html;
            },
            timeout: 5000,
            complete: function () {                
                var html = '<a href="http://my.go.vn/?id=' + commentReturn.Data.USERID +'"><img src="' + getAvatarUrl(commentReturn.Data.USERID, 36) + '" /></a>';
                html += '<p>';
                html += '<a href="http://my.go.vn/?id=' + commentReturn.Data.USERID +'" class="name">' + commentReturn.Data.USERNAME + ' </a><span>';
                html += commentReturn.Data.MESSAGE;
                html += '</span><br /><span class="date">' + formatDateTime(commentReturn.Data.DATETIME) + '</span> ';
                html += '<span class="set"><a href="#" class="err">&nbsp;</a><a href="#" class="del">&nbsp;</a></span>'
                html += '</p>';                
                dataresponse.Comments[dataresponse.Comments.length] = commentReturn.Data;
                $("#boxComment").append($('<li>').attr('id', 'cmt_' + dataresponse.Comments.length).append(html));              
            }
        });
        $("#txtRawContent").data("sceditor").val("");
        HideCommentBox();
    }
    function DoVote() {         
        var likeReturn;
        $.ajax({
            type: "POST",
            cache: false,
            url: "Resources.ashx?module=contribution&action=insertvote",
            data: { "articleId": <%= articleId %>},
            success: function (html) {
                likeReturn = html;
            },
            timeout: 5000,
            complete: function () {                
                $("#boxLike").html("<div class=\"csslikeCommentl\">Bạn đã thích nội dung này</div>");
            }
        });
        $("#txtRawContent").data("sceditor").val("");
        HideCommentBox();
    }
    var dataresponse;
    function GetContribution() {        
        $.ajax({
            type: "POST",
            cache: false,
            url: "Resources.ashx?module=contribution&action=getcontribution",
            data: { "articleId": <%= articleId %>},
            success: function (html) {
                dataresponse = html;
            },
            timeout: 5000,
            complete: function () {    
                        
                //var arrContri = eval("[" + dataresponse + "]");
                if(dataresponse.Comments.length > 5){
                    $("#boxComment").append($('<li>').attr('id', 'iter_0').append($('<a>').attr('href', 'javascript:;').attr('onclick', 'GetAllComment();').html("Xem tất cả " + dataresponse.Comments.length + " bình luận")));
                }
                if(dataresponse.Likes.length > 0){
                    var isMe = -1;
                    $.each(dataresponse.Likes, function(index, value) { 
                        if(value.USERID == curentUser){
                            isMe = index;
                        }
                    });
                    if(dataresponse.Likes.length > 2){
                        if(isMe >= 0){
                            $("#boxLike").hide();
                            $("#boxComment").append($('<li>').attr('id', 'cmt_0').append("<a href=\"http://my.go.vn/?id=" + curentUser + "\">Bạn</a> và <a href=\"javascript:;\" onclick=\"GetAllLike()\">" + (dataresponse.Likes.length - 1) + " người</a> đã thích nội dung này"));
                        }
                        else{
                            $("#boxComment").append($('<li>').attr('id', 'cmt_0').append("<a href=\"http://my.go.vn/?id=" + dataresponse.Likes[0].USERID +"\">" + dataresponse.Likes[0].USERNAME + "</a>, <a href=\"http://my.go.vn/?id=" + dataresponse.Likes[1].USERID +"\">" + dataresponse.Likes[1].USERNAME + "</a> và <a href=\"javascript:;\" onclick=\"GetAllLike()\">" + (dataresponse.Likes.length - 2) + " người</a> đã thích nội dung này"));
                        }
                    }
                    else{
                        if(isMe >= 0)
                            $("#boxLike").hide();
                        var html = '';
                        $.each(dataresponse.Likes, function(index, value) { 
                            if(index == 0)
                                html += "<a href=\"http://my.go.vn/?id=" + value.USERID +"\">" + value.USERNAME + "</a>";
                            else
                                html += ", <a href=\"http://my.go.vn/?id=" + value.USERID +"\">" + value.USERNAME + "</a>";
                        });
                        $("#boxComment").append($('<li>').attr('id', 'cmt_0').append(html + " đã thích nội dung này"));
                    }
                }
                var index = dataresponse.Comments.length - 4;
                if(index < 0)
                    index = 0;
                for(var i = index; i < dataresponse.Comments.length; i++)
                {
                    var html = '<a href="http://my.go.vn/?id=' + dataresponse.Comments[i].USERID +'"><img src="' + getAvatarUrl(dataresponse.Comments[i].USERID, 36) + '" /></a>';
                    html += '<p>';
                    html += '<a href="http://my.go.vn/?id=' + dataresponse.Comments[i].USERID +'" class="name">' + dataresponse.Comments[i].USERNAME + ' </a><span>';
                    html += dataresponse.Comments[i].MESSAGE;
                    html += '</span><br /><span class="date">' + formatDateTime(dataresponse.Comments[i].DATETIME) + '</span> ';
                    html += '<span class="set"><a href="#" class="err">&nbsp;</a><a href="#" class="del">&nbsp;</a></span>'
                    html += '</p>';
                    $("#boxComment").append($('<li>').attr('id', 'cmt_' + (i + 1)).append(html));
                }
            }
        });
    }
    function GetAllLike(){
        var html = '';
        $.each(dataresponse.Likes, function(index, value) { 
            if(index == 0)
                html += "<a href=\"http://my.go.vn/?id=" + value.USERID +"\">" + value.USERNAME + "</a>";
            else
                html += ", <a href=\"http://my.go.vn/?id=" + value.USERID +"\">" + value.USERNAME + "</a>";
        });
        $("#cmt_0").html(html + " đã thích nội dung này");
    }
    function GetAllComment(){
        for(var i = 0; i < dataresponse.Comments.length - 4; i++)
        {
            var html = '<a href="http://my.go.vn/?id=' + dataresponse.Comments[i].USERID +'"><img src="' + getAvatarUrl(dataresponse.Comments[i].USERID, 36) + '" /></a>';
            html += '<p>';
            html += '<a href="http://my.go.vn/?id=' + dataresponse.Comments[i].USERID +'" class="name">' + dataresponse.Comments[i].USERNAME + ' </a><span>';
            html += dataresponse.Comments[i].MESSAGE;
            html += '</span><br /><span class="date">' + formatDateTime(dataresponse.Comments[i].DATETIME) + '</span> ';
            html += '<span class="set"><a href="#" class="err">&nbsp;</a><a href="#" class="del">&nbsp;</a></span>'
            html += '</p>';
            $("#cmt_" + (dataresponse.Comments.length - 3)).before($('<li>').attr('id', 'cmt_' + (i + 1)).append(html));
        }
        $("#iter_0").hide();
    }
    GetContribution();
</script>
